<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="renderer" content="webkit" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>千峰教育大前端Vue教学</title>
  <script src="https://cdn.staticfile.org/petite-vue/0.4.1/petite-vue.umd.min.js"></script>
</head>

<body style="margin:100px;font-size:22px;">
  <div v-scope="Child({ count: 0, name: '第一个' })">
    <div>全局 count = {{ __store.count }}</div>
    <div>全局 count = {{ store.count }}</div>
    <div>name = {{ name }}</div>
    <div>num = {{ num }}</div>
    <div><button @click="add">num++</button></div>
  </div>
  <hr>
  <div v-scope="Child({ count: 8, name: '第二个' })">
    <div>全局 count = {{ store.count }}</div>
    <div><button @click="store.inc">全局 count++</button></div>
    <div>name = {{ name }}</div>
    <div>num = {{ num }}</div>
    <div><button @click="add">num++</button></div>
  </div>

  <script>
    const { createApp, reactive } = PetiteVue;
    const __store = reactive({
      count: 0,
      inc() {
        this.count++
      }
    });

    function Child(props) {
      return {
        ...props,
        num: props.count,
        add() {
          this.num++
        },
      }
    }
    __store.inc(); // 提前执行
    createApp({
      store: __store, // 全局注册
      Child, // 注册组件
    }).mount()
  </script>
</body>

</html>